<template>
  <div class="Navbar">
    <div class="banner" @click="toHome">FruitShop</div>
    <div class="account">
      <span @click="toMe">admin</span> <span @click="logOut">登出</span>
    </div>
  </div>
</template>

<script>
import { defineComponent } from 'vue'
import router from '../router'
export default defineComponent({
  setup() {
    const toMe = () => router.push({ name: 'my-account' })
    const logOut = () => {
      localStorage.removeItem('token')
      router.push({ name: 'login' })
    }
    const toHome = () => router.push({ name: 'dashboard' })
    return { toMe, logOut, toHome }
  },
})
</script>

<style lang="scss">
@import '../assets/styles/_var.scss';
.Navbar {
  height: $nav-heught;
  background: $gray-8;
  box-sizing: border-box;
  display: flex;
  padding: $pad-1 $pad-2;
  line-height: 40px;
  color: $gray-5;
  user-select: none;
  .banner {
    font-size: 20px;
    font-weight: bold;
    letter-spacing: 0.5px;
    cursor: pointer;
    &:hover {
      color: $gray-6;
    }
  }
  .account {
    margin-left: auto;
    display: flex;
    align-items: center;
    span:nth-child(1):hover {
      color: $green;
      cursor: pointer;
    }
    span:nth-child(2) {
      display: inline-block;
      border: 1px solid $gray-6;
      font-size: 12px;
      color: $gray-6;
      margin-left: $pad-2;
      height: 20px;
      line-height: 20px;
      padding: 0 $pad-1;
      cursor: pointer;
      &:hover {
        color: $green;
        border: 1px solid $green;
      }
    }
  }
}
</style>
